home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / sossnt.zip / SOSSNT / SRC / NFS.H < prev    next >
C/C++ Source or Header  |  1993-04-03  |  13KB  |  485 lines

  1. /*
  2.  *  nfs.h -- header file for nfs server
  3.  *
  4.  *  Author:
  5.  *      See-Mong Tan, 6/12/88
  6.  *  Modified by:
  7.  *    Rich Braun @ Kronos, 2/15/91
  8.  *  Revision history:
  9.  *  
  10.  * $Log: nfs.h_v $
  11.  * Revision 1.5  1991/05/13  17:52:17  richb
  12.  * Release 3.2.
  13.  *
  14.  * Revision 1.4  1991/04/11  20:42:53  richb
  15.  * Release 3.1.
  16.  *
  17.  * Revision 1.3  1991/03/15  22:42:02  richb
  18.  * Changed revision date.
  19.  *
  20.  */
  21.  
  22. /* $Id: nfs.h_v 1.5 1991/05/13 17:52:17 richb Exp $ */
  23.  
  24. #define VERSION_NUM "3.4"
  25. #define VERSION_DATE "3 Mar 93"
  26.  
  27. #define NFS_PROGRAM ((u_long) 100003)
  28. #define NFS_VERSION ((u_long) 2)
  29. #define NFS_PORT 2049
  30.  
  31. /* procedure definitions for version two of NFS protocol */
  32. #define NFS_NULL 0
  33. #define NFS_GETATTR 1
  34. #define NFS_SETATTR 2
  35. #define NFS_ROOT 3        /* not supported */
  36. #define NFS_LOOKUP 4
  37. #define NFS_READLINK 5        /* not supported */
  38. #define NFS_READ 6
  39. #define NFS_WRITECACHE 7    /* not supported */
  40. #define NFS_WRITE 8
  41. #define NFS_CREATE 9
  42. #define NFS_REMOVE 10
  43. #define NFS_RENAME 11
  44. #define NFS_LINK 12        /* not supported in DOS */
  45. #define NFS_SYMLINK 13        /* not supported in DOS */
  46. #define NFS_MKDIR 14
  47. #define NFS_RMDIR 15
  48. #define NFS_READDIR 16
  49. #define NFS_STATFS 17
  50.  
  51.   /* initializes NFS server */
  52. extern bool_t nfs_init();
  53.  
  54. /* NFS server procedures */
  55.   /* does nothing */
  56. extern void nfs_null();
  57.   /* get file attributes */
  58. extern void nfs_getattr();
  59.   /* set file attributes */
  60. extern void nfs_setattr();
  61.   /* reads a file */
  62. extern void nfs_read();
  63.   /* writes a file */
  64. extern void nfs_write();
  65.   /* file system status */
  66. extern void nfs_statfs();
  67.   /* read directory */
  68. extern void nfs_readdir();
  69.   /* directory lookup */
  70. extern void nfs_lookup();
  71.   /* create file */
  72. extern void nfs_create();
  73.   /* make a directory */
  74. extern void nfs_mkdir();
  75.   /* remove a file */
  76. extern void nfs_remove();
  77.   /* remove a directory */
  78. extern void nfs_rmdir();
  79.   /* rename a file */
  80. extern void nfs_rename();
  81.   /* link a file */
  82. extern void nfs_link();
  83.   /* create symbolic link */
  84. extern void nfs_symlink();
  85.  
  86. /* error routines */
  87.   /* write when file system is read only */
  88. extern void nfserr_readonlyfs();
  89.   /* call was an error */
  90. extern void nfs_error();
  91.  
  92. /* imported from unfs.h -- SUN user level NFS file server */
  93.  
  94. /* %W% %E% UNFSSRC */
  95.  
  96. /*
  97.  * Copyright (c) 1986 Sun Microsystems, Inc.
  98.  */
  99.  
  100. #define    NFS_MAXDATA    1024
  101. #define RD_SIZ        NFS_MAXDATA
  102. #define WR_SIZ        NFS_MAXDATA
  103. /* path and filename length parameters */
  104. #define    NFS_MAXNAMLEN    255
  105. #define    NFS_MAXPATHLEN    512
  106.  
  107. /*
  108.  * NFS mount option flags
  109.  * WARNING: These must not overlap the mount flags in vfs.h!
  110.  */
  111. #define    NFSMNT_SOFT    0x010000    /* soft mount (hard is default) */
  112. #define    NFSMNT_WSIZE    0x020000    /* set write size */
  113. #define    NFSMNT_RSIZE    0x040000    /* set read size */
  114.  
  115. /*
  116.  * Error status
  117.  * Should include all possible net errors.
  118.  * For now we just cast errno into an enum nfsstat.
  119.  */
  120. enum nfsstat {
  121.     NFS_OK = 0,            /* no error */
  122.     NFSERR_PERM=EPERM,        /* Not owner */
  123.     NFSERR_NOENT=ENOENT,        /* No such file or directory */
  124.     NFSERR_IO=EIO,            /* I/O error */
  125.     NFSERR_NXIO=ENXIO,        /* No such device or address */
  126.     NFSERR_ACCES=EACCES,        /* Permission denied */
  127.     NFSERR_EXIST=EEXIST,        /* File exists */
  128.     NFSERR_NODEV=ENODEV,        /* No such device */
  129.     NFSERR_NOTDIR=ENOTDIR,        /* Not a directory*/
  130.     NFSERR_ISDIR=EISDIR,        /* Is a directory */
  131.     NFSERR_FBIG=EFBIG,        /* File too large */
  132.     NFSERR_NOSPC=ENOSPC,        /* No space left on device */
  133.     NFSERR_ROFS=EROFS,        /* Read-only file system */
  134.     NFSERR_NAMETOOLONG=ENAMETOOLONG,/* File name too long */
  135.     NFSERR_NOTEMPTY=ENOTEMPTY,    /* Directory not empty */
  136.     NFSERR_DQUOT=WSAEDQUOT,        /* Disc quota exceeded */
  137.     NFSERR_STALE=WSAESTALE,        /* Stale NFS file handle */
  138.     NFSERR_WFLUSH,            /* write cache flushed */
  139.     NFSERR_INVAL=EINVAL        /* invalid parameter */
  140. };
  141. #define    puterrno(error)        ((enum nfsstat)error)
  142. #define    geterrno(status)    ((int)status)
  143.  
  144. /*
  145.  * File types
  146.  */
  147. enum nfsftype {
  148.     NFNON = 0,
  149.     NFREG = 1,        /* regular file */
  150.     NFDIR = 2,        /* directory */
  151.     NFBLK = 3,        /* block special */
  152.     NFCHR = 4,        /* character special */
  153.     NFLNK = 5        /* symbolic link */
  154. };
  155.  
  156. /*
  157.  * Size of an fhandle in bytes
  158.  */
  159. #define    NFS_FHSIZE    32
  160.  
  161. /*
  162.  * File access handle
  163.  * This structure is supposed to be opaque from the client side.
  164.  * It is handed out by a server for the client to use in further
  165.  * file transactions.
  166.  */
  167. struct fhs {
  168.     dev_t    fh_fsid;             /* filesystem id */
  169.     u_long    fh_fno;                /* file number */
  170.     time_t    fh_fgen;            /* file generation */
  171.                         /* fh_fgen not used in SOS */
  172. };
  173.  
  174. /* the size of fhs varies between machines, and the FHANDLE can
  175.  * be at most 32 bytes.  This means that the length of the
  176.  * path name must vary.  This is invisible from the client
  177.  * side.  It is only to keep the code clean.
  178.  */
  179. #define FH_PN    NFS_FHSIZE - sizeof(struct fhs)
  180.  
  181. typedef struct {
  182.     struct fhs f;                /* file itself */
  183.     struct fhs p;                /* parent file */
  184.     char    fh_pn[FH_PN];            /* pathname */
  185. } fhandle_t;
  186.  
  187. /* pcomp_t not used in SOS */
  188. /*
  189.  * Component name
  190.  * This structure contains the component in a pathname.
  191.  */
  192. typedef struct {
  193.     char    p_comp[NFS_MAXNAMLEN+1];    /* component name */
  194. } pcomp_t;
  195.  
  196. /* pname_t not used in SOS */
  197. /*
  198.  * Pathname
  199.  * This structure contains the pathname to a file on the server side.
  200.  * It is mapped from the file handle.
  201.  */
  202. typedef struct {
  203.     char    p_name[NFS_MAXPATHLEN];    /* pathname */
  204. } pname_t;
  205.  
  206. /*
  207.  * Arguments to remote write and writecache
  208.  */
  209. struct nfswriteargs {
  210.     fhandle_t    wa_fhandle;    /* handle for file */
  211.     u_long        wa_begoff;    /* beginning byte offset in file */
  212.     u_long        wa_offset;      /* current byte offset in file */
  213.     u_long        wa_totcount;    /* total write count (to this offset)*/
  214.     u_long        wa_count;    /* size of this write */
  215.     char        *wa_data;    /* data to write (up to NFS_MAXDATA) */
  216. };
  217.  
  218.  
  219. /*
  220.  * File attributes
  221.  */
  222. struct nfsfattr {
  223.     enum nfsftype    na_type;    /* file type */
  224.     u_long        na_mode;    /* protection mode bits */
  225.     u_long        na_nlink;    /* # hard links */
  226.     u_long        na_uid;        /* owner user id */
  227.     u_long        na_gid;        /* owner group id */
  228.     u_long        na_size;    /* file size in bytes */
  229.     u_long        na_blocksize;    /* prefered block size */
  230.     u_long        na_rdev;    /* special device # */
  231.     u_long        na_blocks;    /* Kb of disk used by file */
  232.     u_long        na_fsid;    /* device # */
  233.     u_long        na_nodeid;    /* inode # */
  234.     struct timeval    na_atime;    /* time of last access */
  235.     struct timeval    na_mtime;    /* time of last modification */
  236.     struct timeval    na_ctime;     /* time of last change */
  237. };
  238.  
  239. /*
  240.  * Arguments to remote read
  241.  */
  242. struct nfsreadargs {
  243.     fhandle_t    ra_fhandle;    /* handle for file */
  244.     u_long        ra_offset;    /* byte offset in file */
  245.     u_long        ra_count;    /* immediate read count */
  246.     u_long        ra_totcount;    /* total read count (from this offset)*/
  247. };
  248.  
  249. /*
  250.  * Status OK portion of remote read reply
  251.  */
  252. struct nfsrrok {
  253.     struct nfsfattr    rrok_attr;    /* attributes, need for pagin*/
  254.     u_long        rrok_count;    /* bytes of data */
  255.     char        *rrok_data;    /* data (up to NFS_MAXDATA bytes) */
  256.     struct buf    *rrok_bp;    /* buffer pointer for bread */
  257.     struct vnode    *rrok_vp;    /* vnode assoc. with buffer */
  258. };
  259.  
  260. /*
  261.  * Reply from remote read
  262.  */
  263. struct nfsrdresult {
  264.     enum nfsstat    rr_status;        /* status of read */
  265.     int        rr_bufsize;        /* bytes allocated for buf */
  266.     union {
  267.         struct nfsrrok    rr_ok_u;    /* attributes, need for pagin*/
  268.     } rr_u;
  269. };
  270. #define    rr_ok        rr_u.rr_ok_u
  271. #define    rr_attr        rr_u.rr_ok_u.rrok_attr
  272. #define    rr_count    rr_u.rr_ok_u.rrok_count
  273. #define    rr_data        rr_u.rr_ok_u.rrok_data
  274. #define rr_bp        rr_u.rr_ok_u.rrok_bp
  275. #define rr_vp        rr_u.rr_ok_u.rrok_vp
  276.  
  277.  
  278. /*
  279.  * File attributes which can be set
  280.  */
  281. struct nfssattr {
  282.     u_long        sa_mode;    /* protection mode bits */
  283.     u_long        sa_uid;        /* owner user id */
  284.     u_long        sa_gid;        /* owner group id */
  285.     u_long        sa_size;    /* file size in bytes */
  286.     struct timeval    sa_atime;    /* time of last access */
  287.     struct timeval    sa_mtime;    /* time of last modification */
  288. };
  289.  
  290.  
  291. /*
  292.  * Reply status with file attributes
  293.  */
  294. struct nfsattrstat {
  295.     enum nfsstat    ns_status;        /* reply status */
  296.     union {
  297.         struct nfsfattr ns_attr_u;    /* NFS_OK: file attributes */
  298.     } ns_u;
  299. };
  300. #define    ns_attr    ns_u.ns_attr_u
  301.  
  302.  
  303. /*
  304.  * NFS_OK part of read sym link reply union
  305.  */
  306. struct nfssrok {
  307.     u_long    srok_count;    /* size of string */
  308.     char    *srok_data;    /* string (up to NFS_MAXPATHLEN bytes) */
  309. };
  310.  
  311. /*
  312.  * Result of reading symbolic link
  313.  */
  314. struct nfsrdlnres {
  315.     enum nfsstat    rl_status;        /* status of symlink read */
  316.     union {
  317.         struct nfssrok    rl_srok_u;    /* name of linked to */
  318.     } rl_u;
  319. };
  320. #define    rl_srok        rl_u.rl_srok_u
  321. #define    rl_count    rl_u.rl_srok_u.srok_count
  322. #define    rl_data        rl_u.rl_srok_u.srok_data
  323.  
  324.  
  325. /*
  326.  * Arguments to readdir
  327.  */
  328. struct nfsrddirargs {
  329.     fhandle_t rda_fh;    /* directory handle */
  330.     u_long rda_offset;    /* offset in directory (opaque) */
  331.     u_long rda_count;    /* number of directory bytes to read */
  332. };
  333.  
  334. /*
  335.  * NFS_OK part of readdir result
  336.  */
  337. struct nfsrdok {
  338.     u_long    rdok_offset;        /* next offset (opaque) */
  339.     u_long    rdok_size;        /* size in bytes of entries */
  340.     bool_t    rdok_eof;        /* true if last entry is in result*/
  341.     struct    udirect *rdok_entries;    /* variable number of entries */
  342. };
  343.  
  344. /*
  345.  * Readdir result
  346.  */
  347. struct nfsrddirres {
  348.     u_long        rd_bufsize;    /* size of client request (not xdr'ed)*/
  349.     enum nfsstat    rd_status;
  350.     union {
  351.         struct nfsrdok rd_rdok_u;
  352.     } rd_u;
  353. };
  354. #define    rd_rdok        rd_u.rd_rdok_u
  355. #define    rd_offset    rd_u.rd_rdok_u.rdok_offset
  356. #define    rd_size        rd_u.rd_rdok_u.rdok_size
  357. #define    rd_eof        rd_u.rd_rdok_u.rdok_eof
  358. #define    rd_entries    rd_u.rd_rdok_u.rdok_entries
  359.  
  360.  
  361. /*
  362.  * Arguments for directory operations
  363.  */
  364. struct nfsdiropargs {
  365.     fhandle_t    da_fhandle;    /* directory file handle */
  366.     char        *da_name;    /* name (up to NFS_MAXNAMLEN bytes) */
  367. };
  368.  
  369. /*
  370.  * NFS_OK part of directory operation result
  371.  */
  372. struct  nfsdrok {
  373.     fhandle_t    drok_fhandle;    /* result file handle */
  374.     struct nfsfattr    drok_attr;    /* result file attributes */
  375. };
  376.  
  377. /*
  378.  * Results from directory operation 
  379.  */
  380. struct  nfsdiropres {
  381.     enum nfsstat    dr_status;    /* result status */
  382.     union {
  383.         struct  nfsdrok    dr_drok_u;    /* NFS_OK result */
  384.     } dr_u;
  385. };
  386. #define    dr_drok        dr_u.dr_drok_u
  387. #define    dr_fhandle    dr_u.dr_drok_u.drok_fhandle
  388. #define    dr_attr        dr_u.dr_drok_u.drok_attr
  389.  
  390. /*
  391.  * arguments to setattr
  392.  */
  393. struct nfssaargs {
  394.     fhandle_t    saa_fh;        /* fhandle of file to be set */
  395.     struct nfssattr    saa_sa;        /* new attributes */
  396. };
  397.  
  398. /*
  399.  * arguments to create and mkdir
  400.  */
  401. struct nfscreatargs {
  402.     struct nfsdiropargs    ca_da;    /* file name to create and parent dir */
  403.     struct nfssattr        ca_sa;    /* initial attributes */
  404. };
  405.  
  406. /*
  407.  * arguments to link
  408.  */
  409. struct nfslinkargs {
  410.     fhandle_t        la_from;    /* old file */
  411.     struct nfsdiropargs    la_to;        /* new file and parent dir */
  412. };
  413.  
  414. /*
  415.  * arguments to rename
  416.  */
  417. struct nfsrnmargs {
  418.     struct nfsdiropargs rna_from;    /* old file and parent dir */
  419.     struct nfsdiropargs rna_to;    /* new file and parent dir */
  420. };
  421.  
  422. /*
  423.  * arguments to symlink
  424.  */
  425. struct nfsslargs {
  426.     struct nfsdiropargs    sla_from;    /* old file and parent dir */
  427.     char            *sla_tnm;    /* new name */
  428.     struct nfssattr        sla_sa;        /* attributes */
  429. };
  430.  
  431. /*
  432.  * NFS_OK part of statfs operation
  433.  */
  434. struct nfsstatfsok {
  435.     u_long fsok_tsize;    /* preferred transfer size in bytes */
  436.     u_long fsok_bsize;    /* fundamental file system block size */
  437.     u_long fsok_blocks;    /* total blocks in file system */
  438.     u_long fsok_bfree;    /* free blocks in fs */
  439.     u_long fsok_bavail;    /* free blocks avail to non-superuser */
  440. };
  441.  
  442. /*
  443.  * Results of statfs operation
  444.  */
  445. struct nfsstatfs {
  446.     enum nfsstat    fs_status;    /* result status */
  447.     union {
  448.         struct    nfsstatfsok fs_fsok_u;    /* NFS_OK result */
  449.     } fs_u;
  450. };
  451. #define    fs_fsok        fs_u.fs_fsok_u
  452. #define    fs_tsize    fs_u.fs_fsok_u.fsok_tsize
  453. #define    fs_bsize    fs_u.fs_fsok_u.fsok_bsize
  454. #define    fs_blocks    fs_u.fs_fsok_u.fsok_blocks
  455. #define    fs_bfree    fs_u.fs_fsok_u.fsok_bfree
  456. #define    fs_bavail    fs_u.fs_fsok_u.fsok_bavail
  457.  
  458. /*
  459.  * XDR routines for handling structures defined above
  460.  */
  461. bool_t xdr_attrstat();
  462. bool_t xdr_creatargs();
  463. bool_t xdr_diropargs();
  464. bool_t xdr_diropres();
  465. bool_t xdr_drok();
  466. bool_t xdr_fattr();
  467. bool_t xdr_fhandle();
  468. bool_t xdr_linkargs();
  469. bool_t xdr_rddirargs();
  470. bool_t xdr_putrddirres();
  471. bool_t xdr_getrddirres();
  472. bool_t xdr_rdlnres();
  473. bool_t xdr_rdresult();
  474. bool_t xdr_readargs();
  475. bool_t xdr_rnmargs();
  476. bool_t xdr_rrok();
  477. bool_t xdr_saargs();
  478. bool_t xdr_sattr();
  479. bool_t xdr_slargs();
  480. bool_t xdr_srok();
  481. bool_t xdr_timeval();
  482. bool_t xdr_writeargs();
  483. bool_t xdr_statfs();
  484.  
  485.